"""
测试配置文件
"""

import pytest
from datetime import datetime, timedelta
from typing import Dict, Any
import json


@pytest.fixture
def sample_user_data():
    """示例用户数据"""
    return {
        "id": 1,
        "email": "test@example.com",
        "name": "测试用户",
        "is_active": True
    }


@pytest.fixture
def sample_calendar_data():
    """示例日历数据"""
    return {
        "name": "测试日历",
        "description": "这是一个测试日历",
        "color": "#007bff",
        "timezone": "Asia/Shanghai",
        "visibility": "private",
        "default_permission": "view",
        "is_default": False
    }


@pytest.fixture
def sample_event_data():
    """示例日程数据"""
    now = datetime.now()
    return {
        "title": "测试日程",
        "description": "这是一个测试日程",
        "location": "测试地点",
        "start_time": now + timedelta(days=1),
        "end_time": now + timedelta(days=1, hours=1),
        "all_day": False,
        "timezone": "Asia/Shanghai",
        "status": "confirmed",
        "priority": "medium",
        "visibility": "private",
        "calendar_id": 1
    }


@pytest.fixture
def sample_recurrence_data():
    """示例重复规则数据"""
    return {
        "repeat_type": "weekly",
        "interval": 1,
        "repeat_days": [1, 2, 3, 4, 5],  # 周一到周五
        "end_date": datetime.now() + timedelta(days=90)
    }


@pytest.fixture
def sample_reminder_data():
    """示例提醒数据"""
    return {
        "reminder_type": "popup",
        "minutes_before": 15,
        "message": "测试提醒"
    }


@pytest.fixture
def sample_tag_data():
    """示例标签数据"""
    return {
        "name": "测试标签",
        "color": "#dc3545",
        "description": "这是一个测试标签"
    }


@pytest.fixture
def test_db_session():
    """测试数据库会话"""
    # 这里可以创建测试数据库会话
    # 现在返回一个模拟对象
    class MockSession:
        def add(self, obj):
            pass
        
        def commit(self):
            pass
        
        def refresh(self, obj):
            pass
        
        def execute(self, query):
            pass
        
        def scalar(self, query):
            return None
        
        def scalars(self, query):
            return []
        
        def close(self):
            pass
    
    return MockSession()


@pytest.fixture
def mock_async_session():
    """模拟异步数据库会话"""
    import asyncio
    from unittest.mock import AsyncMock
    
    session = AsyncMock()
    session.add = AsyncMock()
    session.commit = AsyncMock()
    session.refresh = AsyncMock()
    session.execute = AsyncMock()
    session.scalar = AsyncMock(return_value=None)
    session.scalars = AsyncMock(return_value=[])
    session.close = AsyncMock()
    
    return session


@pytest.fixture
def test_headers():
    """测试请求头"""
    return {
        "Authorization": "Bearer test-token",
        "Content-Type": "application/json"
    }


@pytest.fixture
def test_client():
    """测试客户端"""
    from fastapi.testclient import TestClient
    from main import app
    
    return TestClient(app)


@pytest.fixture
def api_test_data():
    """API测试数据"""
    return {
        "calendar_create": {
            "name": "API测试日历",
            "description": "API测试描述",
            "color": "#28a745",
            "timezone": "Asia/Shanghai",
            "visibility": "private",
            "default_permission": "view",
            "is_default": False
        },
        "event_create": {
            "title": "API测试日程",
            "description": "API测试描述",
            "location": "API测试地点",
            "start_time": "2024-01-15T10:00:00",
            "end_time": "2024-01-15T11:00:00",
            "all_day": False,
            "timezone": "Asia/Shanghai",
            "status": "confirmed",
            "priority": "medium",
            "visibility": "private",
            "calendar_id": 1
        },
        "search_params": {
            "keyword": "测试",
            "start_date": "2024-01-01T00:00:00",
            "end_date": "2024-12-31T23:59:59",
            "page": 1,
            "page_size": 20
        }
    }